package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HospitalSubscribeMedicalExaminerInfoMapper;
import com.ruoyi.system.domain.HospitalSubscribeMedicalExaminerInfo;
import com.ruoyi.system.service.IHospitalSubscribeMedicalExaminerInfoService;

/**
 * 体检人信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-30
 */
@Service
public class HospitalSubscribeMedicalExaminerInfoServiceImpl implements IHospitalSubscribeMedicalExaminerInfoService 
{
    @Autowired
    private HospitalSubscribeMedicalExaminerInfoMapper hospitalSubscribeMedicalExaminerInfoMapper;

    /**
     * 查询体检人信息
     * 
     * @param id 体检人信息主键
     * @return 体检人信息
     */
    @Override
    public HospitalSubscribeMedicalExaminerInfo selectHospitalSubscribeMedicalExaminerInfoById(Long id)
    {
        return hospitalSubscribeMedicalExaminerInfoMapper.selectHospitalSubscribeMedicalExaminerInfoById(id);
    }

    /**
     * 查询体检人信息列表
     * 
     * @param hospitalSubscribeMedicalExaminerInfo 体检人信息
     * @return 体检人信息
     */
    @Override
    public List<HospitalSubscribeMedicalExaminerInfo> selectHospitalSubscribeMedicalExaminerInfoList(HospitalSubscribeMedicalExaminerInfo hospitalSubscribeMedicalExaminerInfo)
    {
        return hospitalSubscribeMedicalExaminerInfoMapper.selectHospitalSubscribeMedicalExaminerInfoList(hospitalSubscribeMedicalExaminerInfo);
    }

    /**
     * 新增体检人信息
     * 
     * @param hospitalSubscribeMedicalExaminerInfo 体检人信息
     * @return 结果
     */
    @Override
    public int insertHospitalSubscribeMedicalExaminerInfo(HospitalSubscribeMedicalExaminerInfo hospitalSubscribeMedicalExaminerInfo)
    {
        verifyPhoneAndIdNumber(hospitalSubscribeMedicalExaminerInfo.getPhone(),hospitalSubscribeMedicalExaminerInfo.getIdNumber());
        hospitalSubscribeMedicalExaminerInfo.setCreateTime(DateUtils.getNowDate());
        return hospitalSubscribeMedicalExaminerInfoMapper.insertHospitalSubscribeMedicalExaminerInfo(hospitalSubscribeMedicalExaminerInfo);
    }

    /**
     * 修改体检人信息
     * 
     * @param hospitalSubscribeMedicalExaminerInfo 体检人信息
     * @return 结果
     */
    @Override
    public int updateHospitalSubscribeMedicalExaminerInfo(HospitalSubscribeMedicalExaminerInfo hospitalSubscribeMedicalExaminerInfo)
    {
        verifyPhoneAndIdNumber(hospitalSubscribeMedicalExaminerInfo.getPhone(),hospitalSubscribeMedicalExaminerInfo.getIdNumber());
        hospitalSubscribeMedicalExaminerInfo.setUpdateTime(DateUtils.getNowDate());
        return hospitalSubscribeMedicalExaminerInfoMapper.updateHospitalSubscribeMedicalExaminerInfo(hospitalSubscribeMedicalExaminerInfo);
    }

    /**
     * 批量删除体检人信息
     * 
     * @param ids 需要删除的体检人信息主键
     * @return 结果
     */
    @Override
    public int deleteHospitalSubscribeMedicalExaminerInfoByIds(Long[] ids)
    {
        return hospitalSubscribeMedicalExaminerInfoMapper.deleteHospitalSubscribeMedicalExaminerInfoByIds(ids);
    }

    /**
     * 删除体检人信息信息
     * 
     * @param id 体检人信息主键
     * @return 结果
     */
    @Override
    public int deleteHospitalSubscribeMedicalExaminerInfoById(Long id)
    {
        return hospitalSubscribeMedicalExaminerInfoMapper.deleteHospitalSubscribeMedicalExaminerInfoById(id);
    }

    /**
     * 校验手机号跟身份证号
     */
    private void verifyPhoneAndIdNumber(String phone,String idNumber){
        if (phone.length() != 11) {
            throw new RuntimeException("手机号长度错误");
        }
        if (!phone.matches("^1[3-9]\\d{9}$")) {
            throw new RuntimeException("手机号格式错误");
        }
        if (idNumber.length() != 15 && idNumber.length() != 18) {
            throw new RuntimeException("身份证长度错误");
        }
    }
}
